<template>
    <app>
        <div>
            <el-card v-for="items in discussFrom" :key="items.id" style="margin-top: 20px" class="box-card">
                <div slot="header" class="clearfix">
                    <span>用户名:{{items.username}}</span><p></p>
                    <el-link icon="el-icon-time" disabled>{{items.createtime}}</el-link>
                </div>

                <div style="margin-bottom:5px">
                    <pre>{{items.content}}</pre>
                </div>

                <el-tooltip class="item" effect="dark" content="删除" placement="top-start">
                    <el-button  style="padding: 5px 5px;" @click="deleteDiscuss(items.id)" type="danger" icon="el-icon-delete" circle></el-button>
                </el-tooltip>
            </el-card>
        </div>
        <div>
            <el-pagination
                    background
                    layout="prev, pager, next"
                    :page-count="thisPageNum"
                    :current-page="thisPageNumPage"
                    @current-change="thisPageNumChange">
            </el-pagination>
        </div>
    </app>
</template>

<script>
    export default {
        name: "discussManagement",
        data(){
            return{
                discussFrom:[],
                thisPageNum:1,

            }
        },
        methods:{
            //查询留言
            getDiscuss(pageNum){
                this.$api.selectDiscuss(pageNum)
                .then(res=>{
                    if (res.code!=200){
                        this.$message.error('网络错误')
                    }else
                    {
                        this.discussFrom=res.data.data;
                        this.thisPageNum=res.data.pages;
                    }
                })
            },
            //分页
            thisPageNumChange(thisPageNumPage){
                this.getDiscuss(thisPageNumPage)
            },
            //删除留言
            deleteDiscuss(discussid){
                this.$api.deleteDiscuss(discussid)
                .then(res=>{
                    if (res.code==200)
                    {
                        this.getDiscuss(1)
                        this.$message.success('删除成功');
                    }
                    else
                    {
                        this.$message.error(res.message);
                    }
                })
            }
        },
        mounted() {
            this.getDiscuss(1);
        }
    }
</script>

<style scoped>

</style>